//
//  TestSounds.cpp
//  NanoIOS
//
//  Created by Jeppe Nielsen on 9/30/13.
//  Copyright (c) 2013 Jeppe Nielsen. All rights reserved.
//

#include "Engine.hpp"
#include "GameWorld.hpp"
#include "SoundSystem.hpp"

using namespace Nano;

class TestSounds : public GameState<TestSounds> {
    
    ALCdevice* device;
    ALCcontext* context;
    GameWorld world;
    GameObject* soundEmitter;
    
    void Initialize() {
        
        ALCdevice* device=alcOpenDevice(NULL);
        if(device==NULL)
        {
            std::cout << "cannot open sound card" << std::endl;
            return;
        }
        ALCcontext* context=alcCreateContext(device,NULL);
        if(context==NULL)
        {
            std::cout << "cannot open context" << std::endl;
            return;
        }
        alcMakeContextCurrent(context);
        
        world.CreateSystem<SoundSystem>();
        
        GameObject* sound = world.CreateObject();
        sound->AddComponent<Sound>()->LoadFromWav("drumloop.wav");
        
        soundEmitter = world.CreateObject();
        soundEmitter->AddComponent<Sound>(sound);
        soundEmitter->AddComponent<SoundEmitter>();
        
        Input.TouchDown += event_handler(this, &TestSounds::TouchDown);
    }
    
    void TouchDown(TouchEvent e) {
        soundEmitter->Clone();
       // soundEmitter->GetComponent<SoundEmitter>()->Playing = !soundEmitter->GetComponent<SoundEmitter>()->Playing();
    }
    
    
    void Update(float dt) {
        world.Update(dt);
    }
    
    void Render() {
        
    }
    
};

/*
int main() {
    Engine e;
    e.Start<TestSounds>();
    return 0;
}
*/
